package org.example.basisobject;

import cn.hutool.core.util.ObjectUtil;

public class Main {

    public static void main(String[] args) {
        try {
            MyClass original = new MyClass(10);
            MyClass cloned =  original.clone(); // 创建原始对象的克隆

            System.out.println("原对象的字段值: " + original.getMyField());
            System.out.println("克隆对象的字段值: " + cloned.getMyField());

            // 修改克隆对象以证明它们是不同实例
            cloned.setMyField(20);

            System.out.println("原对象的字段值: " + original.getMyField());
            System.out.println("修改后克隆对象的字段值: " + cloned.getMyField());

            MyClass2 original2 = new MyClass2(10);
            MyClass2 cloned2 =(MyClass2) original2.clone();// 创建原始对象的克隆

            System.out.println("2原对象的字段值: " + original2.getMyField());
            System.out.println("2克隆对象的字段值: " + cloned2.getMyField());

            // 修改克隆对象以证明它们是不同实例
            cloned2.setMyField(20);

            System.out.println("2原对象的字段值: " + original2.getMyField());
            System.out.println("2修改后克隆对象的字段值: " + cloned2.getMyField());



        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
    }
}
